package gemini.castor.ui.server.service.impl;

import gemini.basic.dto.SearchProductCriteria;
import gemini.basic.manager.ProductManager;
import gemini.basic.model.Product;
import gemini.basic.model.ProductType;
import gemini.castor.ui.client.service.SearchProductService;
import gemini.castor.ui.server.service.AbstractSingleService;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SearchProductServiceImpl extends
        AbstractSingleService<ProductManager> implements
        SearchProductService {

    @SuppressWarnings("unused")
	private final Log logger = LogFactory
            .getLog(SearchProductServiceImpl.class);



	@Override
	public ArrayList<Product> findProduct(SearchProductCriteria criteria) {
		List<Product> resultList = getServerManager().findProduct(criteria);
		ArrayList<Product> result = duplicate(resultList);
		return result;
	}


	@Override
	public ArrayList<ProductType> getAllCategory() {
		List<ProductType> resultList = getServerManager().getAllCategory();
		ArrayList<ProductType> result = null;
		
		if(resultList != null){
			result = new ArrayList<ProductType>(resultList.size());
			for (ProductType proType : resultList) {
				result.add(duplicateExcludeFields(proType));
			}
		}
		return result;
	}
}
